package day10;

import day10.inheritableThreadLocal.InTools;
import day10.inheritableThreadLocal.ThreadAA;
import day10.join.MyThread;
import day10.threadLocal.ThreadA;
import day10.threadLocal.ThreadB;
import day10.threadLocal.Tools;

/**
 * <>
 * <详细描述>
 *
 * @Author WANG.SONG.
 * @Date 2019/3/13 0013 22:25
 * @see
 */
public class Run {
    public static void join(){
        MyThread myThread =new MyThread();
        myThread.start();
        try {
            myThread.join();
            System.out.println("mian线程等待myThread完成后执行");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     *  ThreadLocal</>
     */
    public static void threadLocal(){
        ThreadA a = new ThreadA();
        ThreadB b = new ThreadB();
        a.start();
        b.start();
        for (int i =0 ;i<100;i++){
            Tools.t1.set("Main"+(i+1));
            System.out.println(Tools.t1.get());
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * InheritableThreadLocal
     */
    public static void inheritableThreadLocal(){
        for (int i = 0; i<10; i++){
            System.out.println("在Main线程取值="+ InTools.ext.get());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        /**
         * join
         */
        //join();
        /**
         * threadLocal
         */
        //threadLocal();
        inheritableThreadLocal();
        ThreadAA aa =new ThreadAA();
        aa.start();
    }

}
